package cn.regexp.business.web.controller;


import cn.hutool.core.util.ObjectUtil;
import cn.regexp.common.base.page.TablePageInfo;
import cn.regexp.domain.ShopUser;
import cn.regexp.query.ShopUserQuery;
import cn.regexp.service.IShopUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 员工控制器
 */
@Controller
@RequestMapping("business/shopUser")
public class ShopUserController {
    //模板前缀
    private static final String prefix = "business/shopUser/";

    @Autowired
    private IShopUserService shopUserService;

    //页面------------------------------------------------------------
    //列表
    @RequiresPermissions("business:shopUser:view")
    @RequestMapping("/listPage")
    public String listPage(){
        return prefix + "list";
    }

    //数据-----------------------------------------------------------
    //列表
    @RequiresPermissions("business:shopUser:list")
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<ShopUser> query(ShopUserQuery qo){
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        QueryWrapper<ShopUser> wrapper = new QueryWrapper<>();
        wrapper.like(ObjectUtil.isNotEmpty(qo.getMobile()), "mobile", qo.getMobile())
                .eq(ObjectUtil.isNotEmpty(qo.getGender()), "gender", qo.getGender())
                .between(ObjectUtil.isAllNotEmpty(qo.getStartTime(), qo.getEndTime()), "register_time", qo.getStartTime(), qo.getEndTime())
                .like(ObjectUtil.isNotEmpty(qo.getKeyword()), "nickname", qo.getKeyword())
                .or()
                .like(ObjectUtil.isNotEmpty(qo.getKeyword()), "username", qo.getKeyword());
        return new TablePageInfo<>(shopUserService.list(wrapper), shopUserService.count(wrapper));
    }
}
